package com.tlx.app;

import java.util.List;

import org.springframework.boot.SpringApplication;
import org.springframework.stereotype.Service;

import com.tlx.core.util.TConfig;
import com.tlx.core.util.TFileUtils;
import com.tlx.core.util.TSpring;
import com.tlx.image.ImageJoinUtils;

@Service
public class ImageService {

    public static void main(String[] args) {
        SpringApplication.run(TConfig.class, args);
        ImageService is = TSpring.getBean(ImageService.class);

        String dirPath = "D:/0";
        int size = 6;
        is.joinDirIncludeSon(dirPath);
    }

    // 合并一个目录下全部图片
    public void joinDirIncludeSon(String dirPath) {
        ImageJoinUtils.joinVerticalByDirIncludeSon(dirPath);
    }

    // 按group合并文件，包括全部子目录
    public void joinGroupByDirIncludeSon(String dirPath, int size) {

        // 先处理当前目录下图片
        joinGroupByDir(dirPath, size);

        // 再递归
        List<String> dirList = TFileUtils.getDirList(dirPath);
        for (String sonPath : dirList) {
            joinGroupByDirIncludeSon(sonPath, size);
        }
    }

    // 按group合并文件，一次一个目录
    public void joinGroupByDir(String dirPath, int size) {
        // Map<String, String> group = RenameGroupUtils.getGroup(dirPath, size);
        // PrintUtils.printMap(group);
        //
        // for (Entry<String, String> entry : group.entrySet()) {
        // String groupId = entry.getKey();
        // String groupName = entry.getValue();
        // List<FilenameBean> imgList = RenameGroupUtils.getFNList(dirPath,
        // size, groupId, TFileUtils.IMG_EXT);
        // List<String> pathList = FilenameBean.convert(imgList);
        // String newName = TlxUtils.PREFIX + groupId + groupName + "." +
        // imgList.get(0).getExt();
        // String newPath = new File(dirPath, newName).getAbsolutePath();
        // ImageJoinUtils.joinVertical(pathList, newPath);
        // ImageQualityUtils.qualitySelf(newPath, 0.25);
        // }
        // RenameFormatUtils.removeSystemId(dirPath);
    }
}
